<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    function copy(obj) {
        //三目运算符判断，如果这个参数是一个数组，就给obj2赋值为空数组；否则赋值为空对象
        var obj2 = Array.isArray(obj) ? [] : {}
        for (var key in obj) {
            //判断，如果obj的键经过typeof判断是一个引用数据类型，就执行递归对数据再进行处理；否则就将obj里的键名对应的值赋值给obj2的键名
            typeof obj === "object" ? obj2[key] = copy(obj[key]) : obj2[key] = obj[key]
        }
        return obj2
    }
    copy(obj)
</script>